home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / octa209s.zip / octave-2.09 / src / fft.cc < prev    next >
C/C++ Source or Header  |  1996-11-03  |  3KB  |  120 lines

  1. /*
  2.  
  3. Copyright (C) 1996 John W. Eaton
  4.  
  5. This file is part of Octave.
  6.  
  7. Octave is free software; you can redistribute it and/or modify it
  8. under the terms of the GNU General Public License as published by the
  9. Free Software Foundation; either version 2, or (at your option) any
  10. later version.
  11.  
  12. Octave is distributed in the hope that it will be useful, but WITHOUT
  13. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  15. for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with Octave; see the file COPYING.  If not, write to the Free
  19. Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  20.  
  21. */
  22.  
  23. #ifdef HAVE_CONFIG_H
  24. #include <config.h>
  25. #endif
  26.  
  27. #include "defun-dld.h"
  28. #include "error.h"
  29. #include "gripes.h"
  30. #include "help.h"
  31. #include "mappers.h"
  32. #include "oct-obj.h"
  33. #include "utils.h"
  34.  
  35. // This function should be merged with Fifft.
  36.  
  37. DEFUN_DLD (fft, args, ,
  38.   "fft (X [, N]): fast fourier transform of a vector")
  39. {
  40.   octave_value_list retval;
  41.  
  42.   int nargin = args.length ();
  43.  
  44.   if (nargin < 1 || nargin > 2)
  45.     {
  46.       print_usage ("fft");
  47.       return retval;
  48.     }
  49.  
  50.   octave_value arg = args(0);
  51.  
  52.   int n_points = arg.rows ();
  53.   if (n_points == 1)
  54.     n_points = arg.columns ();
  55.  
  56.   if (nargin == 2)
  57.     {
  58.       double dval = args(1).double_value ();
  59.       if (xisnan (dval))
  60.     error ("fft: NaN is invalid as the N_POINTS");
  61.       else
  62.     n_points = NINT (dval);
  63.     }
  64.  
  65.   if (error_state)
  66.     return retval;
  67.  
  68.   if (n_points < 0)
  69.     {
  70.       error ("fft: number of points must be greater than zero");
  71.       return retval;
  72.     }
  73.  
  74.   int arg_is_empty = empty_arg ("fft", arg.rows (), arg.columns ());
  75.  
  76.   if (arg_is_empty < 0)
  77.     return retval;
  78.   else if (arg_is_empty || n_points == 0)
  79.     return Matrix ();
  80.  
  81.   if (arg.is_real_type ())
  82.     {
  83.       Matrix m = arg.matrix_value ();
  84.  
  85.       if (! error_state)
  86.     {
  87.       if (m.rows () == 1)
  88.         m.resize (1, n_points, 0.0);
  89.       else
  90.         m.resize (n_points, m.columns (), 0.0);
  91.       retval = m.fourier ();
  92.     }
  93.     }
  94.   else if (arg.is_complex_type ())
  95.     {
  96.       ComplexMatrix m = arg.complex_matrix_value ();
  97.  
  98.       if (! error_state)
  99.     {
  100.       if (m.rows () == 1)
  101.         m.resize (1, n_points, 0.0);
  102.       else
  103.         m.resize (n_points, m.columns (), 0.0);
  104.       retval = m.fourier ();
  105.     }
  106.     }
  107.   else
  108.     {
  109.       gripe_wrong_type_arg ("fft", arg);
  110.     }
  111.  
  112.   return retval;
  113. }
  114.  
  115. /*
  116. ;;; Local Variables: ***
  117. ;;; mode: C++ ***
  118. ;;; End: ***
  119. */
  120.